<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<title>使用说明</title>

	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
</head>
<body>

<div class="container mt-2" >
	  <div style="font-size: 16px;font-weight: bold;" class="mb-3">
			
			<span>用户管理</span>

	  </div>
	  <div class="form-group">
	    <label for="reg-user">用户</label>
	    <input type="text" class="form-control" id="name"   disabled="disabled">
	    
	  </div>
	  <div class="form-group">
	    <label for="reg-pwd">支付宝账号</label>
	    <input type="text" class="form-control" id="zfb" placeholder="请输入你的支付宝账号">
	    <small class="form-text text-muted">不能超过50个字符。用于返利自动转账到你的支付宝. <span style="color: red">必填</span></small>
	  </div>
	  <div class="form-group">
	    <label for="reg-pwd">支付宝账号实名认证</label>
	    <input type="text" class="form-control" id="zfbName" placeholder="请输入你的支付宝账号实名">
	    <small class="form-text text-muted">不能超过50个字符。转账的时候方便确认.
	  </div>
	  <div class="form-group">
	    <label for="reg-pwd">微信号</label>
	    <input type="text" class="form-control" id="weixin" placeholder="请输入微信号">
	    <small class="form-text text-muted">请输入常用微信号，方便联系. <span style="color: red">必填</span></small>
	  </div>
	  <div class="form-group">
	    <label for="reg-pwd">邀请码</label>
	    <input type="text" class="form-control" id="userCode" disabled="disabled"  />
	    <small class="form-text text-muted">邀请别人注册填写此邀请码，别人买东西，也也可以得到一定比例的返利</small>
	  </div>
	  <div class="form-group">
	    <label for="reg-pwd">邀请码注册链接</label>
	    <!-- <button type="button" class="btn btn-success userRegCode-btn" >复制下面链接</button> -->
	    <input type="text" class="form-control mt-2" id="userRegCode" disabled="disabled"  />
	    <small class="form-text text-muted">复制此链接邀请别人注册成为自己的邀请码用户</small>
	  </div>
	  <!-- <button type="button" class="btn btn-success codeUser-btn">查看被邀请人员列表</button> -->

	  <span  style="color:green;font-size: 14px;">您一共邀请了 
	  	<span class="code-users" style="color: red;font-weight: bold;font-size: 16px;">0</span>
	  	 位用户
	  </span>
	  <br /> <hr/><br />
	  <button  id="btn-saveUserInfo" class="btn btn-primary">保存</button>

	  <button  class="btn btn-secondary ml-3  return-index">返回主页</button>

</div>

<!-- jQuery first, then Tether, then Bootstrap JS.  B-->

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
 
<!-- jQuery first, then Tether, then Bootstrap JS. E -->

<script>
//去左右空格;
function trim(s){
    return s.replace(/(^\s*)|(\s*$)/g, "");
}

(function(){

	function init(){
		$.ajax({
				   type: "POST",
				   url: "/mytk/tklUser/webToken",
				   dataType:"json",
				   success: function(msg){

					   	//console.info(msg)

					   	if(msg.code == 200){

					   		$('#name').val(msg.body.name);
					   		$('#zfb').val(msg.body.zfb);
					   		$('#zfbName').val(msg.body.zfbName);
					   		$('#weixin').val(msg.body.weixin);
					   		$('#userCode').val(msg.body.userCode);
					   		var ucodeUrl = "http://118.31.64.124/longin-register.html?regPar=reg&codeReg=";
					   		ucodeUrl+=msg.body.userCode;
							ucodeUrl+="&u=true";

							//http://118.31.64.124/longin-register.html?regPar=reg&codeReg=123&u=true

							$("#userRegCode").val(ucodeUrl);
					   	}else{
					   		alert(msg.msg)
					   	}
				   },
				   error: function(XMLHttpRequest, textStatus, errorThrown) {

						alert("请求失败！请联系管理员");
				   }
				})
	}

	function codeUsers(){
		$.ajax({
				   type: "POST",
				   url: "/mytk/codeUser/pageData",
				   data: "page=1&size=1",
				   dataType:"json",
				   success: function(msg){

					   	console.info(msg)

					   	if(msg.code == 200){
					   		var userNumber = msg.body.total;
					   		$(".code-users").text(userNumber);
					   	
					   	}else{
					   		alert(msg.msg)
					   	}
				   },
				   error: function(XMLHttpRequest, textStatus, errorThrown) {

						alert("请求失败！请联系管理员");
				   }
				})
	}

	init();
	codeUsers();
	function saveUserInfo(){

		var zfb =  trim($("#zfb").val());
		var zfbName = trim($("#zfbName").val());
		var weixin = trim($("#weixin").val());

		if(!zfb || zfb.length == 0){
				alert("支付宝账号不能为空");
				return;
		}

		if(!weixin || weixin.length == 0){
				alert("微信账号不能为空");
				return;
		}

		$.ajax({
		   type: "POST",
		   url: '/mytk/tklUser/updateOne',
		   data: "&zfb="+zfb+"&zfbName="+zfbName+"&weixin="+weixin,
		   dataType:"json",
		   success: function(msg){

			   	console.info(msg)

			   	if(msg.code == 200){
			   		alert('保存成功');
					window.location.href='index.html';
			   	}else{
			   		alert(msg.msg)
			   	}

		   },
		   error: function(XMLHttpRequest, textStatus, errorThrown) {


				alert("请求失败！请联系管理员");
		   }


		})

	}

	$("#btn-saveUserInfo").off().on("click",saveUserInfo);

}())


$(".return-index").off().on("click", function(){
		window.location.href='index.html';
});

// $(".userRegCode-btn").off().on("click", function(){
// 		var coedeUrl = $("#userRegCode").val();

// 	window.clipboardData.setData("Text",coedeUrl);
// 	alert("复制成功!");
// });
$(".codeUser-btn").off().on("click", function(){
		window.location.href='code-user.html';
});


</script>

</body>
</html>